//
//  CommonFunctionViewController.m
//  HXBaseProjectDemo
//
//  Created by YaSha_Tom on 2018/2/5.
//  Copyright © 2018年 亚厦装饰股份有限公司. All rights reserved.
//

#import "CommonFunctionViewController.h"
#import "CommonCollectionReusableView.h"
#import "CommonCollectionViewCell.h"

@interface CommonFunctionViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

//注册头标识
static NSString *const reuseIdentifierHeader = @"ApplicationCycleView";
//注册cell标识
static NSString *const reuseIdentifier = @"ApplicationCell";

@implementation CommonFunctionViewController

- (UICollectionViewFlowLayout *)flowLayout {
    if (!_flowLayout) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.itemSize = CGSizeMake(375.0/4.0, 375.0/4.0);
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing  = 0;
        flowLayout.headerReferenceSize = CGSizeMake(375, 147);
        [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
        _flowLayout = flowLayout;
    }
    return _flowLayout;
}

- (void)initSubviews {
    [super initSubviews];
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 375, 667) collectionViewLayout:self.flowLayout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
    [self.collectionView registerClass:[CommonCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:reuseIdentifierHeader];
    [self.collectionView registerClass:[CommonCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    [self.view addSubview:self.collectionView];
}
#pragma mark - UICollectionViewDataSource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataSourceArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CommonCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    CommonApplicationModel *cellModel = self.dataSourceArray[indexPath.row];
    [cell setCellModel:cellModel];
    return cell;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    UICollectionReusableView *supplementaryView;
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        CommonCollectionReusableView *applicationBannerView = (CommonCollectionReusableView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:reuseIdentifierHeader forIndexPath:indexPath];
        applicationBannerView.imageView.image = [UIImage imageNamed:!_imageName ? @"benner" : _imageName];
        supplementaryView = applicationBannerView;
    }
    return supplementaryView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
